import axios from 'axios'
// 创建axios实例
axios.defaults.withCredentials = true// 允许跨域设置，不然可能因为拿不到cookie而报错

const service = axios.create({
  withCredentials: true,
  baseURL: 'https://autumnfish.cn/',
  timeout: 15000 // 请求超时时间
})

service.interceptors.request.use(config => {
  // config.headers['Accept'] = 'application/json'
  return config
}, error => {
  Promise.reject(error)
})

// respone拦截器
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    if (error.response) {
      const res = error.response.data

      return Promise.reject(res)
    } else {
      return Promise.reject(error)
    }
  }
)

export default service
